<?php
session_start();
if(session_is_registered($_REQUEST["user_id"])){}
else 
die("<a href='../../index.php'>PLEASE LOGIN AGAIN... </a>");


$type = $_REQUEST["type"];
$folder_id = $_REQUEST["folder_id"];
$user_id = $_GET["user_id"];

include("../../connect.php");

echo "<form action='add_file.php' method='post' enctype='multipart/form-data'>";
echo "File: <input type='File' name='MyFile'>";
echo "<br> <input type='submit' value='Save' name='btn'>";
echo "<input type='hidden' value='$folder_id' name='folder_id'>";
echo "<input type='hidden' value='$user_id' name='user_id'>";
echo "</form>";

if(isset($_POST["btn"])){
$target_path = "folders/";

$folder_id   = $_POST["folder_id"];	
$user_id = $_POST["user_id"];


$text_name = basename( $_FILES['MyFile']['name']);
//echo "ddd";
//die($text_name);
$target_path = $target_path .$text_name;
move_uploaded_file($_FILES['MyFile']['tmp_name'], $target_path);  	


echo $query = "insert into articles values('',$folder_id,'$text_name','tree/$target_path',1,0,$user_id)";
$res = mysql_query($query); 
if($res)
echo "<script> window.location='../files.php?user_id=$user_id' </script>";
}
?>